<!--
 * @Description: 项目入口
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-10-11
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2024-04-16
-->
<script setup lang="ts">
  import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
  import { ref } from 'vue'

  import { getOpenid, getToken, getUserId } from '@/utils/storage'

  import { saveUserInfo, wxAuth } from './utils/auth'

  onLaunch(() => {
    console.log(getUserId(), 'getUserId()')
    if (getOpenid() && getToken() && getUserId()) {
      saveUserInfo()
      return
    }
    wxAuth()
  })
  onShow(async () => {
    updateVersion()
  })
  onHide(() => {})

  /**
   * 版本更新（强制更新）
   */
  const updateVersion = () => {
    const updateManager = uni.getUpdateManager()
    updateManager.onCheckForUpdate((res) => {
      if (res.hasUpdate) {
        updateManager.onUpdateReady(() => updateManager.applyUpdate())
      }
    })
  }
</script>

<style></style>
